import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_category.dart';
import 'package:flutter_learn_vi/src/page/topic/topic_details_page.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/12.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///答题主页面
class TopicSelectTwoPage extends StatefulWidget {
  final String pageTitle;
  final String categoryOne;
  final List<CategoryBean> categoryList;

  TopicSelectTwoPage({this.categoryOne,this.categoryList, this.pageTitle});

  @override
  _TestPageState createState() => _TestPageState();
}

class _TestPageState extends State<TopicSelectTwoPage> {
  bool isElect = false;
  CategoryBean categoryBean;

  @override
  Widget build(BuildContext context) {
    if (isElect) {
      return TopicDetilsPage(
        themTitle: widget.pageTitle,
        categoryOne: widget.categoryOne,
        categoryTwo: categoryBean.categoryCode,
      );
    }
    return Container(
      color: Colors.grey[200],
      child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          CategoryBean bean = widget.categoryList[index];
          return Container(
            margin: EdgeInsets.only(top: 2),
            color: Colors.white,
            child: ListTile(
              onTap: () {
                setState(() {
                  isElect = true;
                  categoryBean = bean;
                });
              },
              leading: ClipOval(
                child: Container(
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: Colors.blueGrey.withOpacity(0.5),
                  ),
                  width: 20,
                  height: 20,
                  child: Text("${index + 1}"),
                ),
              ),
              title: Text("${bean.categoryName}"),
              trailing: Icon(Icons.arrow_forward_ios),
            ),
          );
        },
        itemCount: widget.categoryList.length,
      ),
    );
  }
}
